/*
 * MarkerUnifier.cpp
 *
 *  Created on: 4 gru 2013
 *      Author: dawid.wysakowicz
 */

#include "MarkerUnifier.hpp"
#include "boost/algorithm/combination.hpp"
#include "common.hpp"

namespace ar
{
namespace utils
{

MarkerUnifier::MarkerUnifier(const size_t peopleCount) : peopleCount_(peopleCount)
{
}

std::list<dna::marker> MarkerUnifier::unify(const dna::marker& allocator)
{
	std::list<dna::marker> variants;
	if (allocator.size() >= peopleCount_ * 2)
	{
		variants.push_back(allocator);
		variants.front().sort();
//		std::sort(variants.front().begin(), variants.front().end());
		return variants;
	}

	std::vector<dna::allel> tmpAllocator(allocator.begin(), allocator.end());
	std::vector<int> v(allocator.size(), 0);
	v.back() = peopleCount_ * 2 - allocator.size();
    do
    {
            dna::marker result;
            for (size_t i = 0; i < v.size(); i++)
            {
                    for (int j = 0; j < v[i]; j++)
                    {
                            result.push_back(tmpAllocator[i]);
                    }
            }
            result.insert(result.end(), allocator.begin(), allocator.end());
            result.sort();
//            std::sort(result.begin(), result.end());
            variants.push_back(result);
    } while (boost::next_combination_counts(v.begin(), v.end()));
    return variants;
}

MarkerUnifier::~MarkerUnifier()
{

}

} /* namespace utils */
} /* namespace ar */
